package com.spring.arch.common.dto.result;

import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;

/**
 * 异常结果集
 */
@NoArgsConstructor
@Setter
@Getter
public class ErrorDetailDTO implements Serializable {
    private static final long serialVersionUID = -6103753349458235753L;

    /**
     * 异常编码
     */
    @ApiModelProperty(value = "异常编码")
    private String code;

    /**
     * 异常消息
     */
    @ApiModelProperty(value = "异常消息", position = 1)
    private String error;

    /**
     * 异常关联的字段
     */
    @ApiModelProperty(value = "字段名（字段校验类异常）", position = 2)
    private String field;


    public ErrorDetailDTO(final String code, final String error) {
        this(code, error, null);
    }

    public ErrorDetailDTO(final String code, final String error, final String field) {
        this.code = code;
        this.error = error;
        this.field = field;
    }

    @Override
    public String toString() {
        return String.format("{code:%s, error:%s, field:%s}", this.code, this.error, this.field);
    }
}
